﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Admin_Login : System.Web.UI.Page
{
    private Entities en = new Entities();
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void bntLogin_Click(object sender, EventArgs e)
    {
        string u = txtUserName.Text;
        string p = txtPassword.Text;
        if (checklogin(u, en.EncodePassword(p,"")) == true)
        {
            Session["AdminID"] = u;
            Response.Redirect("Default.aspx");
        }
        else {
            txtUserName.Text = "";
            txtPassword.Text = "";
            Label1.Text = "UserName or Password not correct! Please try again!";
        }

    }
    private bool checklogin(string u, string p)
    {
        DataAccess da = new DataAccess();
        SqlConnection sconn = da.SqlConn();
        sconn.Open();
        SqlCommand cmd = new SqlCommand("select * from tb_Admin where username= '" + u + "' and password ='" + p+ "'", sconn);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            sconn.Close();
            return true;
        }
        sconn.Close();
        return false;
    }
}
